interface Store {
  dispatch: Function
  getState: Function
}
// reudxThunk可以让redux dispatch一个函数
// const action = {
//   type: 'add',
//   payload: 100
// }
// store.dispath(dispatch => {
//   setTimeout(() => dispatch(action), 1000)
// })

export const reduxThunk = (store: Store) => (next: Function) => (action: any) => {
  if (action instanceof Function) {
    const dispatch = (action: Object) => {
      next(action)
    }
    action(dispatch, store.getState)
  } else {
    next(action)
  }
}